<template>
  <BasicModal v-bind="$attrs" @register="registerModal" :title="getTitle" width="700px" :height=400>
<!--    日志编号  日志模块  业务类型  方法名称  请求方式  操作类别  操作人员  请求URL 操作ip 请求参数  返回参数  操作状态
错误信息 操作时间
-->
    <a-card>
      <a-descriptions :column="2">
        <a-descriptions-item label="日志编号">{{ detail.operId}} </a-descriptions-item>
        <a-descriptions-item label="日志模块">{{ detail.title}} </a-descriptions-item>
        <a-descriptions-item label="业务类型">{{ detail.businessType}} </a-descriptions-item>
        <a-descriptions-item label="方法名称">{{ detail.method}} </a-descriptions-item>
        <a-descriptions-item label="请求方式">{{ detail.requestMethod}} </a-descriptions-item>
        <a-descriptions-item label="操作类别">{{ detail.operatorType}} </a-descriptions-item>
        <a-descriptions-item label="操作人员">{{ detail.operName}} </a-descriptions-item>
        <a-descriptions-item label="请求URL">{{ detail.operUrl}} </a-descriptions-item>
        <a-descriptions-item label="操作ip">{{ detail.operIp}} </a-descriptions-item>
        <a-descriptions-item label="请求参数">{{ detail.operParam}} </a-descriptions-item>
        <a-descriptions-item label="操作状态">{{ detail.status}} </a-descriptions-item>
        <a-descriptions-item label="错误信息">{{ detail.errorMsg}} </a-descriptions-item>
        <a-descriptions-item label="操作时间" :span="2">{{ detail.operTime}} </a-descriptions-item>
        <a-descriptions-item label="返回参数" :span="2">
          <CodeEditor v-model:value="detail.jsonResult" :mode="modeValue" />
        </a-descriptions-item>
      </a-descriptions>
    </a-card>
  </BasicModal>
</template>
<script lang="ts" setup>
import { BasicModal, useModalInner } from "@/components/Modal";
import { ref } from "vue";
import { CodeEditor, MODE } from '@/components/CodeEditor';
import { useDict } from "@/utils/dict/dict";
const dict:any = ref({});
useDict("log_bussiness_type","log_status","log_operator_type").then((res) => {
  console.log(res);
  dict.value = res;
});
const modeValue = ref<MODE>(MODE.JSON);
const getTitle =  '操作日志详情';
defineOptions({ name: 'sysLogDetail' });
const detail = ref({
  operId: '',
  title: '',
  businessType: '',
  method: '',
  requestMethod: '',
  operatorType: '',
  operName: '',
  operUrl: '',
  operIp: '',
  operParam: '',
  jsonResult: '',
  status: '',
  errorMsg: '',
  operTime: '',
});
const [registerModal, { setModalProps, closeModal }] = useModalInner(async (data) => {
  setModalProps({ confirmLoading: false });
  detail.value = data.record;
  detail.value.businessType = findLabel('log_bussiness_type',detail.value.businessType);
  detail.value.status = findLabel('log_status',detail.value.status);
  detail.value.operTime = timestampToTime(detail.value.operTime);
  detail.value.operatorType = findLabel('log_operator_type',detail.value.operatorType);
});
function findLabel(type,value){
  let label = '';
  dict.value[type].forEach(item => {
    if(item.value == value){
      label = item.label;
    }
  });
  return label;
}
//时间戳转换时间函数
function timestampToTime(timestamp) {
  const date = new Date(timestamp);
  const Y = date.getFullYear() + "-";
  const M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-';
  const D = date.getDate() < 10 ? '0'+date.getDate() + ' ' : date.getDate() + ' ';
  const h = date.getHours() + ':';
  const m = date.getMinutes() + ':';
  const s = date.getSeconds();
  return Y+M+D+h+m+s;
}
</script>
